package allod.som.upgma

import allod.som.Lattice.NeuronLocation
import allod.som.{LabeledLattice, Lattice}
import scala.List

/**
 * Created by IntelliJ IDEA.
 * User: allod
 * Date: 21 лют 2010
 * Time: 18:12:43
 */

abstract class Cluster {
  def name(): String

  def weight(): Int

  def height(): Double

  def getClusters(level: Int): List[Cluster]

  def getIdentityClusters: List[IdentityCluster]
}

case class IdentityCluster(val neuron: NeuronLocation) extends Cluster {
  val name = "id" + neuron._1 + ":" + neuron._2

  val weight = 1

  val height = 0.0

  def getClusters(level: Int) = List(this)

  def getIdentityClusters = List(this)
}

case class CompositeCluster(val leftChild: Cluster, val rightChild: Cluster,
                            val name: String, val height: Double) extends Cluster {
  def this(leftChild: Cluster, rightChild: Cluster) =
    this (leftChild, rightChild, leftChild.name + "::" + rightChild.name, 0)

  val weight = leftChild.weight + rightChild.weight

  def getClusters(level: Int) =
    if (level > 0)
      leftChild.getClusters(level - 1) ::: rightChild.getClusters(level - 1)
    else
      List(this)

  def getIdentityClusters = leftChild.getIdentityClusters ::: rightChild.getIdentityClusters
}